/*
 * This class displays a logout screen for the admin/clerk. The user can either
 * go back to the previous screen or distroy the current authentication instance.
 */

/*
 * Logout.java
 *
 * Created on 24-Apr-2011, 16:48:22
 */
package pos.ui.screen;

import pos.auth.Authentication;
import pos.ui.screen.administrator.AdministratorConsole;

/**
 *
 * @author Parvez
 */
public class Logout extends javax.swing.JFrame {

    Customer cust;
    String msg;
    private String nodeTitle = "Logout Scren";
    
    /** Creates new form Logout */
    public Logout() {
        initComponents();
        setSize(500, 300);
        setTitle(nodeTitle);
    }
    
    /**
     * Parameterised constructor for users using the customer screen to logout
     * 
     * @param cust Customer screen object
     */
    public Logout(Customer cust) {
        this.cust = cust;
        this.msg = "You are already logged in.";
        initComponents();
        setSize(500, 300);
        setTitle(nodeTitle);
    }
    
    /**
     * Parameterised constructor for users using the admin console to logout
     * 
     * @param adCons 
     */
    public Logout(AdministratorConsole adCons) {
//        setTitle("Logout");
        this.nodeTitle = "Logout";
        Authentication.logOut();
        adCons.dispose();
    }
    
    /**
     * Parameterised constructor for the displaying a custom message on the 
     * logout window.
     * 
     * @param message Message to be shown on the logout screen
     */
    public Logout(String message) {
        this.msg = message;
        initComponents();
        setSize(500, 300);
        setTitle("Logout Scren");
    }
    
    /**
     * String for showing the node title
     * 
     * @return String Name of the node in the tree
     */
    @Override
    public String toString(){
        return nodeTitle;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        message = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        TitleText = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jButton1.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jButton1.setText("Log-out");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(94, 116, 140, 60);

        message.setFont(new java.awt.Font("Verdana", 0, 10));
        message.setForeground(new java.awt.Color(204, 0, 0));
        message.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        getContentPane().add(message);
        message.setBounds(80, 184, 0, 21);

        jButton2.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(252, 116, 120, 60);

        TitleText.setFont(new java.awt.Font("Verdana", 0, 24));
        TitleText.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TitleText.setText("Digishop POS");
        getContentPane().add(TitleText);
        TitleText.setBounds(145, 11, 176, 46);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 153, 0));
        jLabel1.setText(this.msg);
        getContentPane().add(jLabel1);
        jLabel1.setBounds(155, 68, 170, 35);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Authentication.logOut();
        this.cust.discountBtn.setEnabled(false);
        this.cust.jButton7.setEnabled(false);
        this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.dispose();
}//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel TitleText;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel message;
    // End of variables declaration//GEN-END:variables
}
